import statemachinestates

class StateMachine(object):
    def __init__(self):
        self.states = (
            statemachinestates.SimpleTextState("test intro", (100,100), statemachinestates.STATE_TITLE),
            statemachinestates.TitleState("test title", (100,100), statemachinestates.STATE_GRAPHICAL_SELECT_ACTION),
            statemachinestates.SelectActionGraphicalState(),
            statemachinestates.AnimateActionGraphicalState(),
            statemachinestates.TurnSummaryState(),
            statemachinestates.GameOverState()
        )
        self.currentStateIndex = statemachinestates.STATE_INTRO
        self.needsEntryState = True
    
    def tick(self):
        currentStateIndex = self.currentStateIndex
        currentState = self.states[currentStateIndex]
        
        if self.needsEntryState:
            currentState.entry()
            self.needsEntryState = False
        
        nextStateIndex = currentState.do()
        
        # print "current=%s next=%s" % (currentStateIndex, nextStateIndex)
        
        if (nextStateIndex != None) and (nextStateIndex != currentStateIndex):
            currentState.exit()
            self.currentStateIndex = nextStateIndex
            self.needsEntryState = True

